{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# <center>零售业数据分析系</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "项目背景\n",
    "- 此次项目数据来自Kaggle，包含了2010年12月1日至2011年12月9日在英国注册的非实体网上零售发生的所有交易。公司主要销售独特的全天候礼品。该公司的许多客户都是批发商。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "> 字段介绍\n",
    "- InvoiceNo: 订单编号，每笔交易有6个整数，退货订单编号开头有字母'C'。\n",
    "- StockCode: 产品编号，由5个整数组成。\n",
    "- Description: 产品描述。\n",
    "- Quantity: 产品数量，有负号的表示退货\n",
    "- InvoiceDate: 订单日期和时间。\n",
    "- UnitPrice: 单价（英镑），单位产品的价格。\n",
    "- CustomerID:客户编号，每个客户编号由5位数字组成。\n",
    "- Country: 国家的名称，每个客户所在国家/地区的名称。\n",
    "\n",
    "> 问题\n",
    "- 1.购买商品数前十的国家是？\n",
    "- 2.交易额前十的国家是？\n",
    "- 3.哪些月份销量较佳？\n",
    "- 4.客单价多少？\n",
    "- 5.用户消费行为分析"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 导入数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "#设置中文标签的显示\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei']  #设置显示中文字体"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\program files\\python\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3146: DtypeWarning: Columns (3,5,6) have mixed types.Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单编号</th>\n",
       "      <th>产品编号</th>\n",
       "      <th>产品描述</th>\n",
       "      <th>产品数量</th>\n",
       "      <th>订单日期和时间</th>\n",
       "      <th>单价（英镑）</th>\n",
       "      <th>客户编号</th>\n",
       "      <th>国家的名称</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>InvoiceNo</td>\n",
       "      <td>StockCode</td>\n",
       "      <td>Description</td>\n",
       "      <td>Quantity</td>\n",
       "      <td>InvoiceDate</td>\n",
       "      <td>UnitPrice</td>\n",
       "      <td>CustomerID</td>\n",
       "      <td>Country</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>536365</td>\n",
       "      <td>85123A</td>\n",
       "      <td>WHITE HANGING HEART T-LIGHT HOLDER</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>2.55</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>536365</td>\n",
       "      <td>71053</td>\n",
       "      <td>WHITE METAL LANTERN</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>536365</td>\n",
       "      <td>84406B</td>\n",
       "      <td>CREAM CUPID HEARTS COAT HANGER</td>\n",
       "      <td>8</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>2.75</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>536365</td>\n",
       "      <td>84029G</td>\n",
       "      <td>KNITTED UNION FLAG HOT WATER BOTTLE</td>\n",
       "      <td>6</td>\n",
       "      <td>12/1/2010 8:26</td>\n",
       "      <td>3.39</td>\n",
       "      <td>17850.0</td>\n",
       "      <td>United Kingdom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541905</th>\n",
       "      <td>581587</td>\n",
       "      <td>22613</td>\n",
       "      <td>PACK OF 20 SPACEBOY NAPKINS</td>\n",
       "      <td>12</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>0.85</td>\n",
       "      <td>12680</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541906</th>\n",
       "      <td>581587</td>\n",
       "      <td>22899</td>\n",
       "      <td>CHILDREN'S APRON DOLLY GIRL</td>\n",
       "      <td>6</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>2.1</td>\n",
       "      <td>12680</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541907</th>\n",
       "      <td>581587</td>\n",
       "      <td>23254</td>\n",
       "      <td>CHILDRENS CUTLERY DOLLY GIRL</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541908</th>\n",
       "      <td>581587</td>\n",
       "      <td>23255</td>\n",
       "      <td>CHILDRENS CUTLERY CIRCUS PARADE</td>\n",
       "      <td>4</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.15</td>\n",
       "      <td>12680</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>541909</th>\n",
       "      <td>581587</td>\n",
       "      <td>22138</td>\n",
       "      <td>BAKING SET 9 PIECE RETROSPOT</td>\n",
       "      <td>3</td>\n",
       "      <td>12/9/2011 12:50</td>\n",
       "      <td>4.95</td>\n",
       "      <td>12680</td>\n",
       "      <td>France</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>541910 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             订单编号       产品编号                                 产品描述      产品数量  \\\n",
       "0       InvoiceNo  StockCode                          Description  Quantity   \n",
       "1          536365     85123A   WHITE HANGING HEART T-LIGHT HOLDER         6   \n",
       "2          536365      71053                  WHITE METAL LANTERN         6   \n",
       "3          536365     84406B       CREAM CUPID HEARTS COAT HANGER         8   \n",
       "4          536365     84029G  KNITTED UNION FLAG HOT WATER BOTTLE         6   \n",
       "...           ...        ...                                  ...       ...   \n",
       "541905     581587      22613          PACK OF 20 SPACEBOY NAPKINS        12   \n",
       "541906     581587      22899         CHILDREN'S APRON DOLLY GIRL          6   \n",
       "541907     581587      23254        CHILDRENS CUTLERY DOLLY GIRL          4   \n",
       "541908     581587      23255      CHILDRENS CUTLERY CIRCUS PARADE         4   \n",
       "541909     581587      22138        BAKING SET 9 PIECE RETROSPOT          3   \n",
       "\n",
       "                订单日期和时间     单价（英镑）        客户编号           国家的名称  \n",
       "0           InvoiceDate  UnitPrice  CustomerID         Country  \n",
       "1        12/1/2010 8:26       2.55     17850.0  United Kingdom  \n",
       "2        12/1/2010 8:26       3.39     17850.0  United Kingdom  \n",
       "3        12/1/2010 8:26       2.75     17850.0  United Kingdom  \n",
       "4        12/1/2010 8:26       3.39     17850.0  United Kingdom  \n",
       "...                 ...        ...         ...             ...  \n",
       "541905  12/9/2011 12:50       0.85       12680          France  \n",
       "541906  12/9/2011 12:50        2.1       12680          France  \n",
       "541907  12/9/2011 12:50       4.15       12680          France  \n",
       "541908  12/9/2011 12:50       4.15       12680          France  \n",
       "541909  12/9/2011 12:50       4.95       12680          France  \n",
       "\n",
       "[541910 rows x 8 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "film_date=pd.read_csv(\"data.csv\",header=None,encoding=\"utf-8\",names=['订单编号','产品编号','产品描述','产品数量','订单日期和时间','单价（英镑）','客户编号','国家的名称'])\n",
    "film_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 541910 entries, 0 to 541909\n",
      "Data columns (total 8 columns):\n",
      " #   Column   Non-Null Count   Dtype \n",
      "---  ------   --------------   ----- \n",
      " 0   订单编号     541910 non-null  object\n",
      " 1   产品编号     541910 non-null  object\n",
      " 2   产品描述     540456 non-null  object\n",
      " 3   产品数量     541910 non-null  object\n",
      " 4   订单日期和时间  541910 non-null  object\n",
      " 5   单价（英镑）   541910 non-null  object\n",
      " 6   客户编号     406830 non-null  object\n",
      " 7   国家的名称    541910 non-null  object\n",
      "dtypes: object(8)\n",
      "memory usage: 16.5+ MB\n"
     ]
    }
   ],
   "source": [
    "film_date.info()\n",
    "data=film_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# data1 = data.drop_duplicates(subset='userId')\n",
    "data1=data[\"产品编号\"]\n",
    "data1.isnull().any(axis=0)\n",
    "# data['time'] = pd.to_datetime(data['time']/1000, unit='s')\n",
    "# data = data[data['time']>=pd.to_datetime('2019-02-05 00:00:00')]\n",
    "# data.set_index(data[\"time\"], inplace=True)\n",
    "# data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
